<template>
  <div class="page">
    <div class="breadcrumb-box">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>猜你喜欢</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="goodsList td-fss">
      <div class="container">
        <ul class="list">
          <li v-for="(item, index) in productList" :key="index">
            <div class="goods-box" @click="_goGoodsDetail(item)">
              <img class="goods-img" :src="item.image" @click="_goGoodsDetail(item)" />
              <div class="goods-name ellipsis" :title="item.store_name">{{ item.store_name }}</div>
              <div class="goods-price td-fbc">
                <span>¥{{ item.price }}</span>
                <img :src="$global.Image.icon_cart" @click.stop="_showGoodsInfo(item)" />
              </div>
            </div>
          </li>
          <div class="nodata" v-if="productList.length == 0">
            <img :src="$global.Image.noGood" />
          </div>
        </ul>
        <div class="pagination-box">
          <el-pagination
            background
            layout="prev, pager, next"
            @current-change="_handelClickPage"
            :page-size="where.limit"
            :total="count"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!-- add cart -->
    <v-add-cart ref="addCart"></v-add-cart>
  </div>
</template>

<script>
import { getHostProducts } from "@api/store";
import addCart from "@components/addCart";

export default {
  components: {
    'v-add-cart': addCart
  },
  data() {
    return {
      productList: [], // 产品列表
      where: {
        page: 1,
        limit: 20
      },
      count: 0
    };
  },
  mounted() {
    this.hostProducts();
  },
  methods: {
    // 获取产品
    hostProducts() {
      getHostProducts(this.where.page, this.where.limit).then(res => {
        this.productList = res.data || []
        this.count = res.count || 0
      });
    },
    // 分页
    _handelClickPage(val) {
      this.where.page = val;
      this.hostProducts();
    },
    // 进入商品详情
    _goGoodsDetail(item) {
      this.$router.push("/detail/" + item.id);
    },
    // 显示商品信息
    _showGoodsInfo(item) {
      this.$refs.addCart.show(item.id)
    }
  }
};
</script>

<style scoped  lang="scss" scoped>
// goods list
.goodsList {
  .top-filter {
    padding: 0 20px 0 40px;
    height: 60px;
    border: solid #eee 1px;
    box-shadow: 0 5px 10px rgba($color: #000000, $alpha: 0.1);
    .filter {
      font-size: 14px;
      color: #999;
      span {
        font-size: 14px;
        display: inline-block;
        margin-right: 40px;
        cursor: pointer;
        display: flex;
        align-items: center;
        img {
          height: 14px;
          margin-left: 4px;
        }
      }
      span:hover {
        color: #DA213D;
      }
      .active {
        color: #DA213D;
      }
    }
  }
  .list {
    margin-top: 40px;
    overflow: hidden;
    min-height: 410px;
    border-top: solid #eee 1px;
    li {
      float: left;
      width: 25%;
      box-sizing: border-box;
      border-right: solid #eee 1px;
      border-bottom: solid #eee 1px;
      padding: 20px 15px;
      .goods-box {
        width: 260px;
        margin: auto;
        .goods-img {
          width: 100%;
          height: 260px;
          display: block;
          cursor: pointer;
          object-fit: cover;
        }
        .goods-name {
          font-size: 16px;
          color: #333;
          height: 30px;
          line-height: 30px;
          margin-top: 10px;
          cursor: pointer;
        }
        .goods-price {
          margin-top: 10px;
          span {
            font-size: 16px;
            font-weight: 600;
            color: #DA213D;
          }
          img {
            display: block;
            width: 23px;
            height: 23px;
            cursor: pointer;
          }
        }
      }
    }
    li:hover {
      background-color: #f8f8f8;
    }
    li:nth-child(4n + 4) {
      border-right: none;
    }
  }
}

.top-search {
  width: 297px;
  height: 40px;
  border: 1px solid #DA213D;
  border-radius: 2px;
  margin-left: 40px;
  overflow: hidden;
  input {
    color: #333;
    height: 40px;
    border: none;
    outline: medium;
    padding: 0 20px;
  }
  .icon-search {
    width: 60px;
    img {
      display: block;
      height: 20px;
      cursor: pointer;
    }
  }
}
</style>
